#ifndef __REGISTER__
#define __REGISTER__

#define SYS_REG_READ(reg, dist) do {            \
    asm volatile("mrs %0, "#reg"":"=r"(dist));   \
}while(0);                                      \

#define SYS_REG_WRITE(reg, val) do {            \
    asm volatile("msr "#reg", %0"::"r"(val));   \
}while(0);                                      \


#define DEFINE_SYS_WRITE(reg)                                   \
static inline unsigned long int sys_write_##reg(unsigned long int val){  \
    SYS_REG_WRITE(reg, val);                                    \
    return val;                                                 \
}                                                               \


#define DEFINE_SYS_READ(reg)                                   \
static inline unsigned long int sys_read_##reg(){              \
    unsigned long int val;                                     \
    SYS_REG_READ(reg, val);                                    \
    return val;                                                 \
}   

#define SYS_MEMORY_READ(reg, dist) do {            \
    asm volatile("ldr x1, ="#reg"");              \
    asm volatile("mov %0, x1":"=r"(dist));   \
}while(0); 

#define DEFINE_MEMORY_READ(reg)                                   \
static inline unsigned long int memory_read_##reg(){              \
    unsigned long int val;                                     \
    SYS_MEMORY_READ(reg, val);                                    \
    return val;                                                 \
}   

// #define READ(reg, dist) do {            \
//     asm volatile("mrs %0, "#reg"":"=r"(dist));   \
// }while(0);    




#endif /* __REGISTER__ */
